package gui;

import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import control.Constants;
import control.Context;
import control.Controller;

public class LoginGui extends JFrame implements ActionListener {
	private static final long serialVersionUID = 1L;
	private JButton btn_register, btn_login;
	private JTextField txt_benutzername;
	private JPasswordField txt_passwort;
	private JLabel lbl_benutzername, lbl_passwort, lbl_falscherBenutzer, lbl_falschesPasswort;
	Context context;
	private Controller _controller;

	public LoginGui(String title, Context context, Controller controller) {
		super(title);
		_controller = controller;
		Container c = getContentPane();
		c.setLayout(null);
		this.context = context;
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(350, 200);
		setResizable(false);
		setLocationRelativeTo(null);
		
		btn_register = new JButton("Registrieren");
		btn_register.setLocation(20,120);
		btn_register.setSize(120,30);
		btn_register.addActionListener(this);
		c.add(btn_register);
		
		btn_login = new JButton("Login");
		btn_login.setLocation(220,120);
		btn_login.setSize(100,30);
		btn_login.addActionListener(this);
		c.add(btn_login);
		
		lbl_benutzername = new JLabel("Benutzername:");
		lbl_benutzername.setLocation(35, 35);
		lbl_benutzername.setSize(90, 25);
		c.add(lbl_benutzername);
		
		txt_benutzername = new JTextField();
		txt_benutzername.setLocation(130, 35);
		txt_benutzername.setSize(120,25);
		c.add(txt_benutzername);
		
		lbl_falscherBenutzer = new JLabel("FEHLER!");
		lbl_falscherBenutzer.setLocation(255, 35);
		lbl_falscherBenutzer.setSize(180, 25);
		lbl_falscherBenutzer.setVisible(false);
		c.add(lbl_falscherBenutzer);
		
		
		lbl_passwort = new JLabel("Passwort:");
		lbl_passwort.setLocation(60, 70);
		lbl_passwort.setSize(60, 25);
		c.add(lbl_passwort);
		
		txt_passwort = new JPasswordField();
		txt_passwort.setLocation(130, 70);
		txt_passwort.setSize(120,25);
		c.add(txt_passwort);
		
		lbl_falschesPasswort = new JLabel("FEHLER!");
		lbl_falschesPasswort.setLocation(255, 70);
		lbl_falschesPasswort.setSize(180, 25);
		lbl_falschesPasswort.setVisible(false);
		c.add(lbl_falschesPasswort);
		
		setVisible(true);
		
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		String cmd = e.getActionCommand();
		switch(cmd){
		case "Login":
			System.exit(0);
		case "Registrieren":
			_controller.newActivity(Constants.ACTIVITY_NEWREGISTERGUI);
		}
		
	}
}
